Re: Ordering 'A', 'B', ..., 'Z', 'AA', 'AB', ... - Mailing list pgsql-general

From Charles Albrecht
Subject Re: Ordering 'A', 'B', ..., 'Z', 'AA', 'AB', ...
Date
Msg-id p05101400b899c36e325d@[206.124.22.67]
Whole thread Raw
In response to Ordering 'A', 'B', ..., 'Z', 'AA', 'AB', ...  (Jon Lapham <lapham@extracta.com.br>)
Responses Re: Ordering 'A', 'B', ..., 'Z', 'AA', 'AB', ...
List pgsql-general
At 4:47 PM -0300 2/20/2002, Jon Lapham wrote:
>Hello folks-
>
>Does anyone have a suggestion on how to order a varchar(2) column
>containing values like: 'A', 'B', ..., 'Z', 'AA', 'AB', ...
>
>What I would like to to return the tuples in this order:
>A
>B
>C
>...
>X
>Y
>Z
>AA
>AB
>...

In transact-sql, I've used a structure something like:

ORDER BY
    CASE WHEN TABLE.MYCOLUMN LIKE '__'
         THEN TABLE.MYCOLUMN
         ELSE ' ' || TABLE.MYCOLUMN END

The syntax may be a little different in pg, though.

It's also easy enough to do in Perl with a custom sort sub.

-Charles
--
Charles Albrecht                                      Euonymic Solutions
charlesa@pobox.com                                       P.O. Box 300623
C>303.619.7596  F>978.334.3061               Denver, Colorado 80203-0623
                http://www.euonymic.net/~charlesa/cv/

pgsql-general by date:

Previous
From: Joe Conway
Date:
Subject: Re: documention on psql?
Next
From: "Dean Hill"
Date:
Subject: Re: documention on psql?